<?php
	$hfbcats 	= getHFBCats();
	$hfbsets 	= getHFBSets();
	
	$headers 	= getHeadersList();
	$footers 	= getFootersList();
	$buttons 	= getButtonsList();
	$borders 	= getBordersList();
	
	if($_REQUEST['item'] > 0)
	{ $item['id'] = $_REQUEST['item']; }
	if($item['id'] > 0)
	{ 
		$item 			= getHFBSet($item['id']); 
		$incats 		= getInHFBCats($item['id'], 4);
	}
	switch ($_POST['action'])
	{
		case 'lista':
			if($_POST['new_name'][0] != '')
			{ addHFBSet($_POST['new_name'][0]); }
			$i=0;
			if($_POST['hfb_id'])
			{
				foreach($_POST['hfb_id'] as $id)
				{
					updateHFBSet($id, $_POST['name'][$i], $_POST['border'][$i], $_POST['header'][$i], $_POST['footer'][$i], $_POST['button'][$i]);
					$i++;
				}
			}
			if($_POST['delete'] > 0)
			{ deleteHFBSet($_POST['delete']); } 
			break;
		case 'editor':
			if($item['id'] > 0)
			{
				if($_POST['border2'] == '')
				{ $_POST['border2'] = -1; }
				if($_POST['h_button'] == '')
				{ $_POST['h_button'] = -1; }
				if($_POST['f_button'] == '')
				{ $_POST['f_button'] = -1; }
				
				updateHFBSet($item['id'], $_POST['name'], $_POST['border'], $_POST['header'], $_POST['footer'], $_POST['button'], $_POST['border2']);
				if($_POST['add_to_cat'] > 0)
				{ addItemToCat($item['id'], 4, $_POST['add_to_cat']);}
				if($_POST['rem_from_cat'] > 0)
				{ removeItemFromCat($item['id'], 4, $_POST['rem_from_cat']);}
			}
			break;
	}
	if($item['id'] > 0)
	{ 
		$item = getHFBSet($item['id']); 
		$incats = getInHFBCats($item['id'], 4);
	}
?>